/**
 * 
 */
package projectg06.grafos;

import java.util.Comparator;

/**
 * @author David
 * @param <T>
 *
 */
public class Vertice implements Comparable<Object>, Comparator<Object>{

	protected static final int A_MINUSC = 97;
	protected int clave;
	protected String nombre;
	protected Integer color;
	protected int grado;
	
	
	public Vertice(int clave, String nombre){
		this.clave = clave;
		this.nombre = nombre;
		this.grado = 0;
		// Sin color
		this.color = 0;
	}
	
	public Vertice(int clave){
		this(clave, "");
		this.nombre = Character.toString(generaNombre(clave));;
	}
	
	/**
	 * 
	 */
	public Vertice() {
		// TODO Auto-generated constructor stub
		this(0,null);
	}

	
	public void pintar(Integer color){
		if(color > 0)
			this.color = color;
	}
	
	public void aumentarGrado(){
		grado++;
	}
	
	public void disminuirGrado(){
		if(grado > 0)
			grado--;
	}
	
	public static char generaNombre(int i){
		return (char)(A_MINUSC + i);
	}
	
	public int obtenerClave(){
		return clave;
	}
	
	public String obtenerNombre(){
		return nombre;
	}
	
	public int obtenerGrado(){
		return grado;
	}
	
	public String toString(){
		return "{ Clave = " + clave + ", Nombre = "
				+ nombre + ", Grado = " + grado + "}"; 
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + clave;
		result = prime * result + grado;
		result = prime * result + ((nombre == null) ? 0 : nombre.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Vertice))
			return false;
		Vertice other = (Vertice) obj;
		if (clave != other.clave)
			return false;
		if (grado != other.grado)
			return false;
		if (nombre == null) {
			if (other.nombre != null)
				return false;
		} else if (!nombre.equals(other.nombre))
			return false;
		return true;
	}

	@Override
	public int compareTo(Object arg0) {
		// TODO Auto-generated method stub
		return this.grado - ((Vertice)arg0).grado;
	}

	@Override
	public int compare(Object arg0, Object arg1) {
		// TODO Auto-generated method stub
		if(((Vertice)arg0).grado > ((Vertice)arg1).grado)
			return 1;
		
		if(((Vertice)arg0).grado < ((Vertice)arg1).grado)
			return -1;
		
		return 0;
	}
	
	

}
